#!/usr/bin/env python

# --------------------------------------
# projects/python/collatz/TestCollatz.py
# Copyright (C) 2009
# Glenn P. Downing
# --------------------------------------

# To run the tests
#     TestCollatz.py

# To document the tests
#     pydoc -w TestCollatz

import main
import unittest

# ----------
# TestReader
# ----------

class TestReader (object) :
    def __init__ (self, s) :
        self.s = s

    def read (self) :
        return self.s

# ----------
# TestWriter
# ----------

class TestWriter (object) :
    def str (self) :
        return self.s

    def write (self, *a) :
        self.s = str(a[0])
        for w in a[1:] :
            self.s += ' '
            self.s += str(w)
        self.s += '\n'

# -----------
# TestCollatz
# -----------

class TestCollatz (unittest.TestCase) :
    # ----
    # read
    # ----

    def test_read (self) :
        reader = TestReader('1 1000000\n')
        main.my_read(reader)
        self.assert_(main.i ==  1)
        self.assert_(main.j == 1000000)

    # ----
    # eval
    # ----

    def test_eval1 (self) :
        main.i =  1
        main.j = 1000000
        main.v =  0
        main.my_eval()
        self.assert_(main.v == 525)

    def test_eval2 (self) :
        main.i =  500
        main.j = 50000
        main.v =  0
        main.my_eval()
        self.assert_(main.v == 324)

    def test_eval3 (self) :
        main.i =  10
        main.j = 15
        main.v =  0
        main.my_eval()
        self.assert_(main.v == 18)

    def test_eval4 (self) :
        main.i =  7000
        main.j = 7001
        main.v =  0
        main.my_eval()
        self.assert_(main.v == 32)

    def test_eval5 (self) :
        main.i =  10
        main.j = 10
        main.v =  0
        main.my_eval()
        self.assert_(main.v == 7)

    def test_eval6 (self) :
        main.i =  588
        main.j = 599
        main.v =  0
        main.my_eval()
        self.assert_(main.v == 119)

    def test_eval7 (self) :
        main.i =  40
        main.j = 600000
        main.v =  0
        main.my_eval()
        self.assert_(main.v == 470)

    def test_eval8 (self) :
        main.i =  41
        main.j = 43
        main.v =  0
        main.my_eval()
        self.assert_(main.v == 110)

    def test_eval9 (self) :
        main.i =  44
        main.j = 45
        main.v =  0
        main.my_eval()
        self.assert_(main.v == 17)

    def test_eval10 (self) :
        main.i =  9001
        main.j = 900001
        main.v =  0
        main.my_eval()
        self.assert_(main.v == 525)

    def test_eval11 (self) :
        main.i =  150
        main.j = 151
        main.v =  0
        main.my_eval()
        self.assert_(main.v == 16)

    def test_eval12 (self) :
        main.i =  1
        main.j = 1
        main.v =  0
        main.my_eval()
        self.assert_(main.v == 1)

    def test_eval13 (self) :
        main.i =  2
        main.j = 3
        main.v =  0
        main.my_eval()
        self.assert_(main.v == 8)

    def test_eval14 (self) :
        main.i =  4
        main.j = 6
        main.v =  0
        main.my_eval()
        self.assert_(main.v == 9)

    def test_eval15 (self) :
        main.i =  5
        main.j = 13
        main.v =  0
        main.my_eval()
        self.assert_(main.v == 20)

    def test_eval16 (self) :
        main.i =  6
        main.j = 6
        main.v =  0
        main.my_eval()
        self.assert_(main.v == 9)

    def test_eval17 (self) :
        main.i =  8
        main.j = 27
        main.v =  0
        main.my_eval()
        self.assert_(main.v == 112)

    def test_eval18 (self) :
        main.i =  59
        main.j = 90
        main.v =  0
        main.my_eval()
        self.assert_(main.v == 116)

    def test_eval19 (self) :
        main.i =  191
        main.j = 233
        main.v =  0
        main.my_eval()
        self.assert_(main.v == 128)

    def test_eval20 (self) :
        main.i =  392
        main.j = 430
        main.v =  0
        main.my_eval()
        self.assert_(main.v == 134)

    def test_eval21 (self) :
        main.i =  310
        main.j = 340
        main.v =  0
        main.my_eval()
        self.assert_(main.v == 144)

    def test_eval22 (self) :
        main.i =  972
        main.j = 1278
        main.v =  0
        main.my_eval()
        self.assert_(main.v == 182)

    def test_eval23 (self) :
        main.i =  855
        main.j = 1419
        main.v =  0
        main.my_eval()
        self.assert_(main.v == 182)

    def test_eval24 (self) :
        main.i =  4784
        main.j = 4819
        main.v =  0
        main.my_eval()
        self.assert_(main.v == 166)

    def test_eval25 (self) :
        main.i =  1175
        main.j = 8884
        main.v =  0
        main.my_eval()
        self.assert_(main.v == 262)

    def test_eval26 (self) :
        main.i =  17219
        main.j = 22971
        main.v =  0
        main.my_eval()
        self.assert_(main.v == 279)

    def test_eval27 (self) :
        main.i =  11093
        main.j = 58376
        main.v =  0
        main.my_eval()
        self.assert_(main.v == 340)

    def test_eval28 (self) :
        main.i =  96680
        main.j = 128436
        main.v =  0
        main.my_eval()
        self.assert_(main.v == 354)

    def test_eval29 (self) :
        main.i =  58227
        main.j = 147071
        main.v =  0
        main.my_eval()
        self.assert_(main.v == 375)

    def test_eval30 (self) :
        main.i =  893424
        main.j = 966826
        main.v =  0
        main.my_eval()
        self.assert_(main.v == 507)

    def test_eval31 (self) :
        main.i =  1
        main.j = 2
        main.v =  0
        main.my_eval()
        self.assert_(main.v == 2)

    def test_eval32 (self) :
        main.i =  4
        main.j = 4
        main.v =  0
        main.my_eval()
        self.assert_(main.v == 3)

    def test_eval33 (self) :
        main.i =  5
        main.j = 8
        main.v =  0
        main.my_eval()
        self.assert_(main.v == 17)

    def test_eval34 (self) :
        main.i =  1
        main.j = 13
        main.v =  0
        main.my_eval()
        self.assert_(main.v == 20)

    def test_eval35 (self) :
        main.i =  4
        main.j = 17
        main.v =  0
        main.my_eval()
        self.assert_(main.v == 20)

    def test_eval36 (self) :
        main.i =  62
        main.j = 64
        main.v =  0
        main.my_eval()
        self.assert_(main.v == 108)

    def test_eval37 (self) :
        main.i =  83
        main.j = 113
        main.v =  0
        main.my_eval()
        self.assert_(main.v == 119)

    def test_eval38 (self) :
        main.i =  8
        main.j = 255
        main.v =  0
        main.my_eval()
        self.assert_(main.v == 128)

    def test_eval39 (self) :
        main.i =  492
        main.j = 497
        main.v =  0
        main.my_eval()
        self.assert_(main.v == 111)

    def test_eval40 (self) :
        main.i =  454
        main.j = 477
        main.v =  0
        main.my_eval()
        self.assert_(main.v == 129)

    def test_eval41 (self) :
        main.i =  384
        main.j = 866
        main.v =  0
        main.my_eval()
        self.assert_(main.v == 171)

    def test_eval42 (self) :
        main.i =  3897
        main.j = 3966
        main.v =  0
        main.my_eval()
        self.assert_(main.v == 189)

    def test_eval43 (self) :
        main.i =  4515
        main.j = 7369
        main.v =  0
        main.my_eval()
        self.assert_(main.v == 262)

    def test_eval44 (self) :
        main.i =  8138
        main.j = 12141
        main.v =  0
        main.my_eval()
        self.assert_(main.v == 268)

    def test_eval45 (self) :
        main.i =  5008
        main.j = 29316
        main.v =  0
        main.my_eval()
        self.assert_(main.v == 308)

    def test_eval46 (self) :
        main.i =  2391
        main.j = 21991
        main.v =  0
        main.my_eval()
        self.assert_(main.v == 279)

    def test_eval47 (self) :
        main.i =  18586
        main.j = 93772
        main.v =  0
        main.my_eval()
        self.assert_(main.v == 351)

    def test_eval48 (self) :
        main.i =  170484
        main.j = 255526
        main.v =  0
        main.my_eval()
        self.assert_(main.v == 443)

    def test_eval49 (self) :
        main.i =  96666
        main.j = 864560
        main.v =  0
        main.my_eval()
        self.assert_(main.v == 525)


    # -----
    # print
    # -----

    def test_print (self) :
        main.i =  1
        main.j = 1000000
        main.v = 525
        writer = TestWriter()
        main.my_print(writer)
        self.assert_(writer.str() == '1 1000000 525\n')

if __name__ == "__main__" :
    unittest.main()
